The present invention relates to the field of array element checking prior to access.
During execution of Java program code, when an element in an array is accessed there are two run-time checks that are performed: a check to see if a reference to the array is null (or does not exist) and a check to see if the value of an index delineating the element is greater than the length of the array.
The first of these checks, to see if the reference to the array is null, can be performed on some operating systems by dereferencing a base address of the array. The use of different operating systems on a computing system that is executing the Java command to access the array may produce different results to this dereference. In the case of many operating systems, such as Linux and Windows, the dereferencing of a null reference will cause a hardware exception. However, on AIX (Advanced IBM Unix) such a dereference of a null reference will result in a successful read of the value 0. While it is obvious that the array does not exist when a hardware exception is produced, dereferencing of the reference producing the value 0 would initially provide the perception that the array exists but has no elements in it.
In AIX, both the first and second checks are performed separately. Each check adds to the length of processing time and also to the amount of processing power used when the program code is executed. Since the reference to the array being accessed in not null and the index is within range for most cases, the two separate checks unnecessarily add to processing time and resources used.